import 'package:easy_refresh/easy_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/inspec_task_page/run_task_page/run_task_controller.dart';

/// 我的任务-执行任务
class RunTaskPage extends StatelessWidget {
  RunTaskPage({super.key});

  final controller = Get.put(RunTaskController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return Container(
          padding: EdgeInsets.symmetric(horizontal: 14.w),
          child: Column(
            children: [
              Container(
                width: double.infinity,
                height: 40.w,
                decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
                child: Row(
                  children: [
                    AppGaps.hGap6,
                    const Icon(Icons.location_on, color: AppColors.font_color_blue, size: 20),
                    Text(
                      '正在进行定位追踪，请打开手机定位功能！',
                      style: TextStyle(
                        fontSize: 12.sp,
                      ),
                    ),
                  ],
                ),
              ).click(() {
                controller.scan(0);
              }),
              AppGaps.vGap14,
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12),
                  ),
                  child: Column(
                    children: [
                      AppGaps.vGap12,
                      Expanded(
                        child: EasyRefresh(
                          onRefresh: controller.getMyTaskUnitList,
                          child: ListView.builder(
                            itemCount: controller.unitList.length,
                            itemBuilder: (cxt, index) {
                              return Container(
                                padding: EdgeInsets.only(
                                  top: 12.w,
                                  bottom: 12.w,
                                  left: 10.w,
                                  right: 10.w,
                                ),
                                margin: EdgeInsets.only(
                                  bottom: 16.w,
                                  right: 12.w,
                                  left: 12.w,
                                ),
                                decoration: BoxDecoration(
                                    border: Border.all(width: 1, color: const Color(0x33587DF5)),
                                    borderRadius: BorderRadius.circular(12),
                                    color: const Color(0xFFF5F6FF)),
                                child: Column(
                                  children: [
                                    Align(
                                      alignment: Alignment.centerLeft,
                                      child: Text(
                                        '${controller.unitList[index].tbBaseRiskUnitName}',
                                        style: TextStyle(
                                          fontSize: 14.sp,
                                          fontWeight: FontWeight.w500,
                                        ),
                                      ),
                                    ),
                                    AppGaps.vGap12,
                                    Row(
                                      children: [
                                        Column(
                                          children: [
                                            Text(
                                              '任务',
                                              style: TextStyle(
                                                fontSize: 12.sp,
                                              ),
                                            ),
                                            AppGaps.vGap4,
                                            Text(
                                              '${controller.unitList[index].completedNum ?? 0}',
                                              style: TextStyle(
                                                fontSize: 16.sp,
                                                color: AppColors.font_color_blue,
                                              ),
                                            ),
                                          ],
                                        ),
                                        AppGaps.hGap50,
                                        Column(
                                          children: [
                                            Text(
                                              '未完成',
                                              style: TextStyle(
                                                fontSize: 12.sp,
                                              ),
                                            ),
                                            AppGaps.vGap4,
                                            Text(
                                              '${controller.unitList[index].incompleteNum ?? '0'}',
                                              style: TextStyle(
                                                fontSize: 16.sp,
                                                color: AppColors.font_color_gray,
                                              ),
                                            ),
                                          ],
                                        ),
                                        const Spacer(),
                                        SvgPicture.asset(
                                          AppImages.icon_bar_scanning,
                                          width: 20.w,
                                          height: 20.w,
                                          colorFilter: const ColorFilter.mode(Color(0xFF495061), BlendMode.srcIn),
                                        ).click(() {
                                          controller.scan(index);
                                        })
                                      ],
                                    )
                                  ],
                                ),
                              ).click(() {
                                controller.goInspectionDetails(controller.unitList[index].tbBaseRiskUnitId);
                              });
                            },
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              )
            ],
          ),
        );
      },
    );
  }
}
